package com.lbd.media.service.impl;

import com.lbd.media.bean.WebLink;
import com.lbd.media.dao.WebLinkRepository;
import com.lbd.media.service.WebLinkService;
import com.lbd.base.service.BaseServiceImpl;
import org.apache.commons.lang.StringUtils;
import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.jpa.domain.Specification;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.Map;


@Service
@Transactional
public class WebLinkServiceImpl extends BaseServiceImpl<WebLink, WebLinkRepository> implements WebLinkService {
    private final Logger log = Logger.getLogger(this.getClass());
    @Autowired
    WebLinkRepository weblinkRepository;

    @Override
    public Specification<WebLink> getSpecification(WebLink weblink) {
        return null;
    }

    /**
     * 构建查询语句和参数
     *
     * @param weblink
     * @param parameter
     * @return
     */
    @Override
    public String buildJpql(WebLink weblink, Map<String, Object> parameter) {
        StringBuilder jpqlBuilder = new StringBuilder("  from  WebLink t   ");
        if (weblink != null) {
            if (StringUtils.isNotBlank(weblink.getName())) {
                jpqlBuilder.append(" and name =: name");
                parameter.put("name", weblink.getName());
            }

        }
        jpqlBuilder.append(" order by createdDate desc ");
        return jpqlBuilder.toString();
    }


}
